/**
 * 過濾 HTML 碼
 * 只取得文字以及連結的部份
 */
function getText(str) {
	var textInsert = true;
	var linkInsert = false;
	var result = "";

	for (i=0;i<str.length;i++) {
		var word = str.substr(i, 1);
		if (textInsert==true) {
			if (str.substr(i, 7)=='<a href') {
				textInsert = false;
				linkInsert = true;
				result += word;
			} else if (word=='<') {
				textInsert = false;
			} else if (str.substr(i, 3)=='<br') {
				textInsert = false;
				result += '<br>';
			} else {
				if (word!="\n"&&word!="\r"&&word!="\t"&&word!=" ") {
					result += word;
				}
			}
		} else if (linkInsert==true) {
			if (word=='>') {
				if (str.substr(i-3, 4)=='</a>') {
					textInsert = true;
					linkInsert = false;
				}
				result += word;
			} else {
				result += word;
			}
		} else {
			if (word=='>') {
				textInsert = true;
			}
		}
	}
	return result;
}

/**
 * 所以的連結都被需修改為另開一個新的視窗
 */
function SetAnchor() {
	for (var i=0;i<document.links.length;i++) {
		document.links[i].target = "_blank";
	}
	var o = $('img');
	for (i=0;i<o.length;i++) {
		o[i].style.border = '0px';
	}
}

/**
 * 移除物件
 */
function remove_msg(b) {
	try
	{
		b.parentNode.removeChild(b);
	}
	catch (e)
	{
		b = null;
	}
	return;
}

/**
 * 取代字串
 * 類似 PHP 提供的 str_replace
 */
function str_replace(search, replace, str) {
	if (str==undefined) return;
	var regex = new RegExp(search, "g");
	return str.replace(regex, replace);
}
